<!DOCTYPE html>
<meta charset="utf-8">
<title>HTMLImageElement#complete</title>
<link rel="help" href="https://html.spec.whatwg.org/#the-img-element">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
"use strict";

async_test(t => {
  const img = document.createElement("img");
  img.src = "file-does-not-exist.png";
  assert_false(img.complete);

  img.onload = img.onerror = t.step_func_done(event => {
    assert_equals(event.type, "error");
    assert_true(img.complete);
  });

  // JSDOM specific: when image loading is not supported (i.e. when node-canvas is not installed), skip the test.
  t.step_timeout(() => {
    t.done();
  }, 1000);
}, "src 404 error");

async_test(t => {
  const img = document.createElement("img");
  img.src = "http://malformed:url";
  assert_false(img.complete);

  img.onload = img.onerror = t.step_func_done(event => {
    assert_equals(event.type, "error");
    assert_true(img.complete);
  });

  // JSDOM specific: when image loading is not supported (i.e. when node-canvas is not installed), skip the test.
  t.step_timeout(() => {
    t.done();
  }, 1000);
}, "src malformed URL");
</script>
